package com.sphd.Restaurant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;

import com.sphd.Restaurant.R;
import com.sphd.Restaurant.adapters.SaleAdapter;
import com.sphd.Restaurant.base.BaseActivity;
import com.sphd.Restaurant.infos.PromotionsInfo;
import com.sphd.Restaurant.utils.AppManager;
import com.sphd.Restaurant.utils.Constants;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SaleActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.my_listView)
    ListView myListView;
    Intent intent;
    List<PromotionsInfo> promotionsInfos;
    SaleAdapter saleAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sale);
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        setToolBar(toolbar, "促销信息", true);
        toolbar.setNavigationOnClickListener(view -> AppManager.getAppManager().finishActivity(this));

        initAdapter();
    }

    private void initAdapter() {
        intent=getIntent();
        Bundle bundle=intent.getExtras();
        promotionsInfos= (List<PromotionsInfo>) bundle.getSerializable(Constants.PROMOTIONSLIST);
        saleAdapter =new SaleAdapter(promotionsInfos);
        myListView.setAdapter(saleAdapter);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 结束Activity&从堆栈中移除
        AppManager.getAppManager().finishActivity(this);
    }
}
